package org.nstack.header.zone;

import org.nstack.header.message.APIEvent;
import org.nstack.header.message.APIMessage;
import org.nstack.header.message.APIParam;
import org.springframework.http.HttpMethod;
import org.nstack.header.notification.ApiNotification;
import org.nstack.header.rest.RestRequest;



@RestRequest(
        path = "/zones/{uuid}/actions",
        isAction = true,
        responseClass = APIChangeZoneStateEvent.class,
        method = HttpMethod.PUT
)
public class APIChangeZoneStateMsg extends APIMessage implements ZoneMessage {

    @APIParam(resourceType = ZoneVO.class)
    private String uuid;

    @APIParam(validValues = {"enable", "disable"})
    private String stateEvent;

    public APIChangeZoneStateMsg() {
    }

    public APIChangeZoneStateMsg(String uuid, String stateEvent) {
        super();
        this.uuid = uuid;
        this.stateEvent = stateEvent;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getStateEvent() {
        return stateEvent;
    }

    public void setStateEvent(String stateEvent) {
        this.stateEvent = stateEvent;
    }

    @Override
    public String getZoneUuid() {
        return getUuid();
    }

    public static APIChangeZoneStateMsg __example__() {
        APIChangeZoneStateMsg msg = new APIChangeZoneStateMsg();
        msg.setUuid(uuid());
        msg.setStateEvent(ZoneStateEvent.enable.toString());
        return msg;
    }

    public ApiNotification __notification__() {
        APIMessage that = this;

        return new ApiNotification() {
            @Override
            public void after(APIEvent evt) {
                ntfy("changed zone state to %s",((APIChangeZoneStateEvent)evt).getInventory().getState())
                        .resource(uuid,ZoneVO.class.getSimpleName())
                        .messageAndEvent(that, evt).done();
            }
        };
    }
}
